<?php

require_once 'config.inc';
require_once '_db.inc';
require_once '_ui.inc';
// Create a database connection
$conn = db_connect(BANK_DB_USER, BANK_DB_PASSWORD);

 ui_print_header('Bank - Choose a Random Money Order to not reveal');
 
// print_r($_POST);

 $moneyOrders = db_do_query($conn,'SELECT * FROM mo_blinded where BATCH=' .$_POST['batch']);
 //$moneyOrders = db_do_query($conn,'SELECT * FROM mo where batch=1');
 
 $N = count($moneyOrders);

 echo <<<END

	<form name="form1" method="post" action="2R_3_CustomerGiveUnblindMO.php">
	<table width="500" border="0" cellspacing="1" cellpadding="3" align=center>
	<tr>
		<td>Money Order Batch</td>
		<td>:</td>
		<td><input name="batch" type="text" size="50" value="$_POST[batch]" READONLY></td>
	</tr>
	<tr>
		<td>Number of Money Orders</td>
		<td>:</td>
		<td><input name="num_mo" type="text" size="50" value="$N" READONLY></td>
	</tr>
	<tr>
END;
		// choose random money order to sign
		$chosen = mt_rand(1, $N); 
		echo '<td colspan = 3 align="center"><input type="hidden" name="chosen" value='.$chosen.'>';
		echo "Money order ". $chosen ." has been chosen to sign".'</br>';
		$N--;
echo <<<END
		<input type="submit" name="unblind" value="Ask Customer to Unblind Left $N Money Orders"> </td>
	</tr>
	</table>
	</form>
END;
?>